<template>
  <div class="classify">
    <DogFood
      :nav="list"
      :page="dog_food_page"
      :brandP="dog_brand_page"
    ></DogFood>

  </div>
</template>

<script>
import jsonp from "jsonp";
import DogFood from "@/components/DogFood";

export default {
  components: { DogFood  },
  data() {
    return {
      list: [],
      dog_food_page: [],
      dog_brand_page: [],
    };
  },
  methods: {
    getData1() {
      let url1 =
        "https://mallcdn.api.epet.com/v3/goods/category/main.html?pet_type=dog&version=358&system=wap&isWeb=1&distinct_id=18f08f9cad3f71-02142ec7ff09d8-26001a51-921600-18f08f9cad41337&_=1714198141688";
      jsonp(url1, {}, (err, data1) => {
        if (err) {
          alert("跨域请求失败");
        } else {
          let data1_ = data1;
          localStorage.setItem("classifynav", JSON.stringify(data1_));
          this.format1(data1_);
        }
      });
    },
    format1(data1) {
      let { categorys } = data1;
      this.list = categorys;
    },

    getData2() {
      let url2 =
        "https://mallcdn.api.epet.com/v3/goods/category/main.html?do=getChildren&owner=5&pet_type=dog&issite=true&version=358&system=wap&isWeb=1&distinct_id=18f08f9cad3f71-02142ec7ff09d8-26001a51-921600-18f08f9cad41337&_=17";
      jsonp(url2, {}, (err, data2) => {
        if (err) {
          alert("跨域请求2失败");
        } else {
          let data2_ = data2;
          localStorage.setItem("dog_food", JSON.stringify(data2_));
          this.format2(data2_);
        }
      });
    },
    format2(data2) {
      let { cate_list } = data2;
      this.dog_food_page = cate_list;
    },

    getData3() {
      let url3 =
        "https://mallcdn.api.epet.com/v3/brand/list/main.html?pet_type=dog&system=wap&isWeb=1&version=303&distinct_id=18f08f9cad3f71-02142ec7ff09d8-26001a51-921600-18f08f9cad41337&_=1714209545495";
      jsonp(url3, {}, (err, data3) => {
        if (err) {
          alert("跨域请求3失败");
        } else {
          let data3_ = data3;
          localStorage.setItem("dog_brand", JSON.stringify(data3_));
          this.format3(data3_);
        }
      });
    },
    format3(data3) {
      let { brand } = data3;
      this.dog_brand_page = brand;
    },
  },
  mounted() {
    let data1 = localStorage.getItem("classifynav");
    let data2 = localStorage.getItem("dog_food");
    let data3 = localStorage.getItem("dog_brand");

    if (data1) {
      this.format1(JSON.parse(data1));
    } else {
      this.getData1();
    }
    if (data2) {
      this.format2(JSON.parse(data2));
    } else {
      this.getData2();
    }
    if (data3) {
      this.format3(JSON.parse(data3));
    } else {
      this.getData3();
    }
  },
};
</script>

<style lang="scss">
</style>